<template>
    <div>
       
        <el-table  :data="tableData.listdata.slice((currentPage4-1)*pageSize4,currentPage4*pageSize4)" style="width: 100%">
          <el-table-column prop="id" label="id"></el-table-column>

          <!-- 修改用户信息 -->

          <el-table-column prop="img" label="img">           
            <template #default="scope">
              <input type="text" v-model="scope.row.img" style="width: 100%">
             </template>           
          </el-table-column> 

          <el-table-column prop="title" label="姓名">           
            <template #default="scope">
              <input type="text" v-model="scope.row.title" style="width: 100%">
             </template>           
          </el-table-column> 

          <el-table-column prop="updata" label="科室">
            <template #default="scope">
              <input type="text" v-model="scope.row.updata" style="width: 100%">
             </template>
          </el-table-column>
          <el-table-column prop="type" label="职位">
            <template #default="scope">
              <input type="text" v-model="scope.row.type" style="width: 100%">
            </template>
          </el-table-column>
            <el-table-column prop="type1" label="医院">
              <template #default="scope">
                <input type="text" v-model="scope.row.type1" style="width: 100%">
              </template>
            </el-table-column>
              <el-table-column prop="type2" label="医院名">
                <template #default="scope">
                  <input type="text" v-model="scope.row.type2" style="width: 100%">
                </template>
              </el-table-column>
                <el-table-column prop="detail" label="详情">
                  <template #default="scope">
                    <input type="text" v-model="scope.row.detail" style="width: 100%">
                  </template>
                </el-table-column>
                  <el-table-column prop="zhanghao" label="账号">
                    <template #default="scope">
                      <input type="text" v-model="scope.row.zhanghao" style="width: 100%">
                    </template>
                  </el-table-column>
                    <el-table-column prop="mima" label="密码">
                      <template #default="scope">
                        <input type="text" v-model="scope.row.mima" style="width: 100%">
                      </template>
          </el-table-column>
          <el-table-column prop="pingjia" label="评价">
            <template #default="scope">
              <input type="text" v-model="scope.row.pingjia" style="width: 100%">
            </template>
          </el-table-column>
          
            <!-- 修改用户信息按钮 -->
            <el-table-column label="操作">
                <template #default="scope">
                  <el-button size="small" style="width: 20px" @click="handleEdit(scope.row,scope.$index)"
                    >修改</el-button
                  >
                  <el-button
                  style="width: 20px"
                    size="small"  
                    type="danger"
                    @click="handleDelete(scope.row,scope.$index)"
                    >删除</el-button
                  >
                  <!-- <el-button size="small" @click="xj(scope.row,scope.$index)"
                    >修改</el-button
                  > -->
                </template>
              </el-table-column>
            <!-- 增加用户信息 -->
              <el-table-column>
                <template #header>
                  <el-button size="small" @click="xj()"
                    >新增</el-button
                  >
                </template>
              </el-table-column>
         <!-- 搜索用户信息框 -->
          <el-table-column>
            <template #header>
              <el-input v-model="search" size="small" placeholder="请输入查询内容" @blur="searchLink"></el-input>
            </template>
          </el-table-column>

        </el-table>
        <!-- 分页 -->
        <el-pagination
         v-model:currentPage="currentPage4"
          v-model:page-size="pageSize4"
          
          :current-page="currentPage4"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.listdata.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
  <!-- 新增的弹出框 -->
  <Ud/>
      </div>
</template>

<script  setup>
    import { ref } from "vue";
    import {onMounted,getCurrentInstance,reactive} from "vue"
    import Ud from "../components/UpdateDialog.vue"
    //引入仓库
import { useCar } from "../store/car.ts";
let store = useCar();
// console.log(store.msg);
let xj = () => {
//   console.log("666");
store.dialogFormVisible = !store.dialogFormVisible;
};
    // let arr=ref("")
    //请求数据库数据
    let tableData=reactive({
        listdata:[]
    })
	let {proxy}=getCurrentInstance()
	onMounted(async ()=>{		
		let res=await proxy.$axios('/homedata')
		console.log(res.data,proxy.$obj,11111111111)
        
        tableData.listdata=res.data
	})

// //引入仓库
// import { useCar } from "../store/car.ts";
// let store = useCar();
// // console.log(store.msg);
// let xj = () => {
// //   console.log("666");
// store.dialogFormVisible = !store.dialogFormVisible;
// };
    
//搜索用户
let search=ref("")
    let searchLink=async ()=>{
  let res=await proxy.$axios.get('/homedata1',{params:{id:search.value}});
  console.log(res.data,proxy.$obj,2222222222222)
      
      tableData.listdata=res.data
}
  
    const currentPage4 = ref(1);
    
    const pageSize4 = ref(15);
    const small = ref(false);
    const background = ref(false);
    const disabled = ref(false);
    
    const handleSizeChange = (val= number) => {
        pageSize4.value=val
    };
    const handleCurrentChange = (val=number) => {
        currentPage4.value=val
    };
    

    //删除、修改
    const handleDelete =async (arg, index) => {
  // console.log(arg)
       let res=await proxy.$axios("/deluser",{params:{id:arg.id}})
       console.log(res)
       if(res.data.affectedRows==1){
        tableData.listdata.splice(index,1)
       }
}
const  handleEdit=async (arg, index) => {
  console.log(arg,123)
        let res=await proxy.$axios("/update1",{params:{...arg}})
        console.log(res,666)
        if(res.data.affectedRows==1){
            alert("修改成功")
        }
}
// //、增加信息
// const xj =async (arg, index) => {
//   // console.log(arg)
//        let res=await proxy.$axios("/xjuser",{params:{...arg}})
//       //  id:tableData.listdata.id,img:tableData.listdata.img,title:tableData.listdata.title,updata:tableData.listdata.updata,type:tableData.listdata.type
//        console.log(res)
//       //  if(res.data.affectedRows==1){
//       //   tableData.listdata.push(1)
//       //  }
// }

    </script>
    <style></style>
